#include<iostream>
#include<string>
using namespace std;
string s1, s2;
int n, m;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		cin >> s1 >> s2;
		if (s1.find(s2) != -1) {
			cout << 0 << endl;
			continue;
		}
		int cnt = 0;
		int ans = -1;
		bool f = 0;
		while (cnt <= 10) {
			s1 = s1 + s1;
			if (s1.find(s2) != -1) {
				ans = cnt + 1;
				break;
			}
			cnt++;
		}
		cout << ans << endl;
	}
	return 0;
}
